package com.weiyuwqj.controller.user;

import com.weiyuwqj.api.service.BasUserInviteIncomeService;
import com.weiyuwqj.api.service.BasUserInviteService;
import com.weiyuwqj.api.service.BasUserInfoService;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.BasUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangyong on 2016/11/24.
 */
@Controller
public class UserInviteController {

    @Autowired
    BasUserInfoService userInfoService;
    @Autowired
    BasUserInviteService userInviteService;
    @Autowired
    BasUserInviteIncomeService userInviteIncomeService;


    //邀请页面
    @RequestMapping(value = "/user/inviteCode")
    public Object inviteCode(HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        BasUserInfo info= userInfoService.getOneByUserId(userId);
        request.getSession().setAttribute("info",info);
        return "main/user/friends";
    }

    /**
     * 邀请人列表
     * @param p
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/user/inviteList",method = RequestMethod.POST)
    public Object list(Paginator p,HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        Map map=new HashMap();
        map.put("userId",userId);
        return userInviteService.getList(p,map);
    }

    /**
     * 邀请收益记录
     * @param p
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/user/inviteIncomeList",method = RequestMethod.POST)
    public Object inviteIncomeList(Paginator p,HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        Map map =new HashMap();
        map.put("userId",userId);
        return userInviteIncomeService.getList(p,map);
    }

    /**
     *  获取用户二维码
     */
    @ResponseBody
    @RequestMapping(value = "/user/getUserQrCode",method = RequestMethod.POST)
    public Object getUserQrCode(HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");
        return null;// EncapsulationResultUtils.encapsulationResultToMap("qrCode", userInfoService.userQrCode(userId));
    }
}
